#include <gvl/math/ieee.hpp>

#define lib_fdlibm_c
#define LUA_LIB

#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"

#include "lj_obj.h"
#include "lj_lib.h"

/* ------------------------------------------------------------------------ */

#define LJLIB_MODULE_fdlibm

#define UNARYF(name) setnumV(L->top++, fd_##name(lj_lib_checknum(L, 1))); return 1

LJLIB_CF(fdlibm_sin)
{ UNARYF(sin); }

LJLIB_CF(fdlibm_cos)
{ UNARYF(cos); }

LJLIB_CF(fdlibm_tan)
{ UNARYF(tan); }

LJLIB_CF(fdlibm_exp)
{ UNARYF(exp); }

LJLIB_CF(fdlibm_atan2)
{
	double x = lj_lib_checknum(L, 1);
	double y = lj_lib_checknum(L, 2);
	setnumV(L->top++, fd_atan2(x, y));
	return 1;
}

#undef UNARYF

/* ------------------------------------------------------------------------ */

#include "lj_libdef.h"

LUALIB_API int luaopen_fdlibm(lua_State *L)
{
  LJ_LIB_REG(L, fdlibm);
  return 1;
}